package com.zzq.my.jetpacks.jectpackapp.ui.act

import android.os.Build
import android.view.View
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.databinding.DialogGoodsSkuLayout2Binding
import com.zzq.my.jetpacks.jectpackapp.ui.fragment.MyBottomSheetDialog

/**
 * 描述：BottomSheetDialog 使用详解，设置圆角、固定高度、默认全屏等
 * 作者：zhuangzeqin
 * 时间: 2022/1/18-17:04
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class BottomSheetActivity : BaseActivity(R.layout.dialog_goods_sku_layout2), View.OnClickListener {
    private val binding by viewBinding(DialogGoodsSkuLayout2Binding::bind)


    /**
     * 初始化数据
     */
    override fun initData() {
//        initDialog()
        binding.btnBottomSheet.setOnClickListener {
            val behavior = BottomSheetBehavior.from(binding.llBottomSheet)
            if (behavior.state == BottomSheetBehavior.STATE_EXPANDED) {
                //如果是展开状态，则关闭，反之亦然
                behavior.state = BottomSheetBehavior.STATE_COLLAPSED
            } else {
                behavior.state = BottomSheetBehavior.STATE_EXPANDED
            }
        }
    }

    /**
     * 初始化操作
     */
    @RequiresApi(Build.VERSION_CODES.O)
    override fun initView() {

    }

    /**
     * BottomSheetDialog
     */
    private fun initDialog()
    {
//        BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
//        bottomSheetDialog.setContentView(R.layout.dialog_goods_sku_layout);
//        //给布局设置透明背景色，让图片突出来
//        bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet)
//            .setBackgroundColor(getResources().getColor(android.R.color.transparent));
//        bottomSheetDialog.show();

       val bottomSheetDialog =  BottomSheetDialog(this)
        bottomSheetDialog.setContentView(R.layout.dialog_goods_sku_layout)
        bottomSheetDialog.delegate.findViewById<View>(R.id.design_bottom_sheet)?.setBackgroundColor(ContextCompat.getColor(this,android.R.color.transparent))
        bottomSheetDialog.show()
        bottomSheetDialog.setCanceledOnTouchOutside(true)

    }

    private fun initBottomSheetDialogFragment() {
        MyBottomSheetDialog().show(supportFragmentManager,"MyBottomSheetDialog")
    }

    /**
     * 初始化点击事件操作
     */
    override fun eventOnClick() {

    }

    override fun onClick(v: View) {

    }

}